//
//  SMSRequestProvider.m
//  SulitLoan
//
//  Created by 虞嘉伟 on 2025/2/26.
//  
  

#import "RiskControlRequestProvider.h"
#import "RiskControlRequest.h"



@implementation RiskControlRequestProvider

+ (void)requestTrackWithRiskControl:(NSString *)productId
                              scene:(RiskControlTrackScene)scene
                              start:(NSInteger)start
                                end:(NSInteger)end
                            success:(void(^)(NSDictionary *dict))success
                            failure:(void(^)(YTKRequest *request))failure {
    RiskControlRequest *request = [RiskControlRequest new];
    request.anxious = productId;
    request.confess = @(scene).stringValue;
    request.halo = @(start).stringValue;
    request.surrounding = @(end).stringValue;
#ifdef DEBUG
//    request.anxious = @"2";
//    request.confess = @"2";
//    request.halo = [NSString stringWithFormat:@"%.0f", NSDate.date.timeIntervalSince1970];
//    request.surrounding = [NSString stringWithFormat:@"%.0f", NSDate.date.timeIntervalSince1970];
#endif
    [request startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSDictionary *dict = request.responseObject;
        if (![dict isKindOfClass:NSDictionary.class]) {
            !failure ?: failure(request);
            return;
        }
        if ([dict[@"weeps"] intValue] == 0) {
            // 成功
            NSLog(@"[风控埋点]数据上报成功: 场景%lu", scene);
            !success ?: success(dict[@"bounding"]);
        } else {
            NSLog(@"[风控埋点]数据上报失败: 场景%lu", scene);
            !failure ?: failure(request);
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSLog(@"[风控埋点]数据上报失败: 场景%lu", scene);
        !failure ?: failure(request);
    }];
}



@end
